﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace BastInfos.Helpers
{
	public class JavaScriptHelper
	{
		private const string INSTANCE_KEY = "_JavaScriptHelper_Instance_";

		public static JavaScriptHelper Instance
		{
			get
			{
				if (HttpContext.Current.Items[INSTANCE_KEY] == null)
					HttpContext.Current.Items[INSTANCE_KEY] = new JavaScriptHelper();
				return (JavaScriptHelper)HttpContext.Current.Items[INSTANCE_KEY];
			}
		}

		private StringBuilder _stringBuilder;

		private JavaScriptHelper()
		{
			_stringBuilder = new StringBuilder();
		}

		public void WriteScript(string script)
		{
			_stringBuilder.Append(script);
		}

		public string Flush()
		{
			string scripts = _stringBuilder.ToString();
			_stringBuilder.Clear();
			return scripts;
		}
	}
}